package com.xkdx.guangguang.pushservice;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;

public class PushServiceModule extends AbsModule {
	public PushInfo pushInfo;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getPushNotification")) {
					pushInfo = parsePushInfo(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private PushInfo parsePushInfo(JSONObject obj) throws Exception{
		PushInfo pushInfo = new PushInfo();
		try {
			if (obj == null) {
				pushInfo.setStatus("null");
				return pushInfo;
			}
			JSONObject stut = (JSONObject) obj.get("Result");
			JSONObject data = (JSONObject) stut.get("DetailInfo");
			if(stut.getString("Status").equals("Success")){
				pushInfo.setStatus(stut.getString("Status"));
				pushInfo.setMessage(data.getString("Message"));
				pushInfo.setObjectType(data.getString("ObjectType"));
				pushInfo.setObjectValue(data.getString("ObjectValue"));
				pushInfo.setReturnObjectType(data.getString("ReturnObjectType"));
				pushInfo.setReturnObjectValue(data.getString("ObjectValue"));
			}else{
				pushInfo.setStatus("Faile");
				return pushInfo;
			}
			

		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return pushInfo;
	}

	class PushInfo {
		String isRead;
		String data;
		String status;
		String Message;
		String ObjectType;
		String ObjectValue;
		String ReturnObjectType;
		String ReturnObjectValue;

		public String getStatus() {
			return status;
		}

		public void setStatus(String status) {
			this.status = status;
		}

		public String getMessage() {
			return Message;
		}

		public void setMessage(String message) {
			Message = message;
		}

		public String getObjectType() {
			return ObjectType;
		}

		public void setObjectType(String objectType) {
			ObjectType = objectType;
		}

		public String getObjectValue() {
			return ObjectValue;
		}

		public void setObjectValue(String objectValue) {
			ObjectValue = objectValue;
		}

		public String getReturnObjectType() {
			return ReturnObjectType;
		}

		public void setReturnObjectType(String returnObjectType) {
			ReturnObjectType = returnObjectType;
		}

		public String getReturnObjectValue() {
			return ReturnObjectValue;
		}

		public void setReturnObjectValue(String returnObjectValue) {
			ReturnObjectValue = returnObjectValue;
		}

		public String getIsRead() {
			return isRead;
		}

		public void setIsRead(String isRead) {
			this.isRead = isRead;
		}

		public String getData() {
			return data;
		}

		public void setData(String data) {
			this.data = data;
		}

	}

}
